package com.xclink.common.mapper.provider;

import org.apache.ibatis.mapping.MappedStatement;

import com.xclink.common.mapper.help.SqlHelper;

import tk.mybatis.mapper.mapperhelper.MapperHelper;
import tk.mybatis.mapper.provider.base.BaseSelectProvider;


public class BaseSelectProviderExt extends BaseSelectProvider {

	public BaseSelectProviderExt(Class<?> mapperClass, MapperHelper mapperHelper) {
		super(mapperClass, mapperHelper);
	}

	/**
	 * 查询扩展
	 *
	 * @param ms
	 * @return
	 */
	public String selectExt(MappedStatement ms) {
		Class<?> entityClass = getEntityClass(ms);
		// 修改返回值类型为实体类型
		setResultType(ms, entityClass);
		StringBuilder sql = new StringBuilder();
		sql.append(SqlHelper.selectAllColumns(entityClass));
		sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
		sql.append(SqlHelper.whereAllIfColumns(entityClass, isNotEmpty()));
		sql.append(SqlHelper.orderByDefault(entityClass));
		return sql.toString();
	}

}
